package com.anysoft.view.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import com.anysoft.base.BaseActivity;

/**
 * Created by wwq on 2017/2/10.
 */

public class DialogUtils {

    private OnEdittextDialogSbtnListener onEdittextDialogSbtnListener;
    private OnContentDialogSbtnListener onContentDialogSbtnListener;

    public void setOnEdittextDialogSbtnListener(OnEdittextDialogSbtnListener onEdittextDialogSbtnListener) {
        this.onEdittextDialogSbtnListener = onEdittextDialogSbtnListener;
    }

    public void setOnContentDialogSbtnListener(OnContentDialogSbtnListener onContentDialogSbtnListener) {
        this.onContentDialogSbtnListener = onContentDialogSbtnListener;
    }

//    public static void showConfirmAlert(final Context context, String title,
//                                        String content, String sbtn) {
//        IcbcDialog dialog = new IcbcDialog(context);
//        dialog.setColor("#FFFFFF");
//        dialog.setCancelable(false);
//        dialog.setAnimationEnable(true);
//        dialog.setTitle(title);
//        dialog.setContentText(content);
//        dialog.setPositiveListener(sbtn, new IcbcDialog.OnPositiveListener() {
//            @Override
//            public void onClick(IcbcDialog dialog) {
//                dialog.dismiss();
//            }
//        }).show();
//    }
//
//    public static void showConfirmAlert(final Context context, String title,
//                                        String content) {
//        showConfirmAlert(context, title, content, "确定");
//    }
//
//    public static void showConfirmAlert(final Context context, String content) {
//        showConfirmAlert(context, "提示", content, "确定");
//    }

    public IcbcDialog edittextAlert(final Context context, String title, String sbtn
            , String cbtn, final String toastContent) {
        IcbcDialog dialog = new IcbcDialog(context);
        dialog.setColor("#FFFFFF");
        dialog.setCancelable(false);
        dialog.setAnimationEnable(true);
        dialog.setTitle(title);
        dialog.setEditTextType(true);
        dialog.setNegativeListener(cbtn, new IcbcDialog.OnNegativeListener() {
            @Override
            public void onClick(IcbcDialog dialog) {
                dialog.dismiss();
            }
        });
        dialog.setPositiveListener(sbtn, new IcbcDialog.OnPositiveListener() {
            @Override
            public void onClick(IcbcDialog dialog) {
                String input = dialog.getEditTextContent();
                if (TextUtils.isEmpty(input)) {
                    Toast.makeText(context, toastContent, Toast.LENGTH_SHORT).show();
                    return;
                }

                if (onEdittextDialogSbtnListener != null) {
                    onEdittextDialogSbtnListener.OnEdittextDialogSbtnClick(input);
                }
                dialog.dismiss();
            }
        }).show();
        return dialog;
    }

    public IcbcDialog contentAlert(final Context context, String title, String content, String sbtn
            , String cbtn) {
        IcbcDialog dialog = null;
        if (dialog == null && !((BaseActivity) context).isFinishing()) {
            dialog = new IcbcDialog(context);
            dialog.setColor("#FFFFFF");
            dialog.setCancelable(false);
            dialog.setAnimationEnable(true);
            dialog.setTitle(title);
            dialog.setContentText(content);
            dialog.setEditTextType(false);
            if (!TextUtils.isEmpty(cbtn)) {
                dialog.setNegativeListener(cbtn, new IcbcDialog.OnNegativeListener() {
                    @Override
                    public void onClick(IcbcDialog dialog) {
                        dialog.dismiss();
                    }
                });
            }
            dialog.setPositiveListener(sbtn, new IcbcDialog.OnPositiveListener() {
                @Override
                public void onClick(IcbcDialog dialog) {
                    if (onContentDialogSbtnListener != null) {
                        onContentDialogSbtnListener.OnContentDialogSbtnClick();
                    }
                    dialog.dismiss();
                }
            }).show();
        }

        return dialog;
    }

    public RegisterSuccessDialog registerSuccess(Context context, String content) {
        RegisterSuccessDialog dialog = new RegisterSuccessDialog(context, content);
        dialog.setCancelable(false);
        dialog.setAnimationEnable(true);
        dialog.setNegativeListener(new RegisterSuccessDialog.OnNegativeListener() {
            @Override
            public void onClick(RegisterSuccessDialog dialog) {
                if (onContentDialogSbtnListener != null) {
                    onContentDialogSbtnListener.OnContentDialogSbtnClick();
                }
                dialog.dismiss();
            }
        }).show();
        return dialog;
    }

    public LoadingDialog loadingDialog(Context context) {
        LoadingDialog dialog = new LoadingDialog(context);
        dialog.setCancelable(false);
        dialog.setAnimationEnable(true);
        dialog.show();
        return dialog;
    }

    public interface OnEdittextDialogSbtnListener {

        /**
         * @param inputContent
         */
        void OnEdittextDialogSbtnClick(String inputContent);
    }

    public interface OnContentDialogSbtnListener {

        void OnContentDialogSbtnClick();
    }
}
